package sgi.client;

import java.io.IOException;
import sgi.message.MessageCreateReport;

import sgi.misc.*;

public class SGICreateReportsController extends SGIController {
	
	public static SGICreateReportsController createReports;
	public static SGICreateReportsUI createReportsUI;

	public enum Color {
		 COMPLAINT_REPORT, DATABASE_REPORT, PACKAGE_REPORT; 
		}
	
	public static SGICreateReportsController create() {
		if( SGICreateReportsController.createReports == null )
		{
			SGICreateReportsController.createReports = new SGICreateReportsController();
			createReportsUI.setController(createReports);
		}
		
		SGICreateReportsController.createReportsUI.setVisible(true);
		return SGICreateReportsController.createReports;
		
	}
	
	public SGICreateReportsController() {
		createReportsUI = new SGICreateReportsUI();
	}

	public void report(int reportType) {
		MessageCreateReport msg = new MessageCreateReport(reportType);
		sendReport(msg);
	}
	
	private void sendReport(MessageCreateReport msg) {
		try {
			(SGIClientConnectionController.createConnection()).handleMessageFromClientUI(msg);
		} catch  (IOException e) {e.printStackTrace();}
	}
	
	@Override
	void handleMessage(Object msg) {
		if (((MessageCreateReport)msg).reportCreated == true)
			switch (((MessageCreateReport)msg).getReportType()) {
			case 0:
				createReportsUI.setMessage("Complaints report created.");
				break;
			case 1:
				createReportsUI.setMessage("Database Status report created.");
				break;
			case 2:
				createReportsUI.setMessage("Package Info report created.");
				break;
			default:
				createReportsUI.setMessage("Uh oh, something went wrong...");
				break;
			}
		
	}
	
	public static void terminate()
	{
		SGICreateReportsController.createReports = null;
		SGICreateReportsController.createReportsUI.setController(null);
		SGICreateReportsController.createReportsUI.setVisible(false);
		SGICreateReportsController.createReportsUI = null;
		SGIUserAccountMenuController.create(null);
	}

}
